<?php
class Common_redis_model{
	public $params=array();
	public $CI=false;  
	public $redis; 
	private $redis_config = array('host' => 'localhost', 'port' => 6379, 'password' => '' ); 
	public function __construct(){
		$this->CI =& get_instance();
		//$this->load->library('redis',array('model'=>'user','channel'=>'user'),'user_redis_model');
		//var_dump($this->user_redis_model->redis_class->add(123457,array('uid'=>123457,'username'=>"LGT",'phone'=>'17027212550')));
		//var_dump($this->user_redis_model->redis_class->get_info(123456));
		//加载redis
		$this->CI->load->config('redis',TRUE);
		$redis_config  = @$this->CI->config->item('data', 'redis');
		if(isset($redis_config['host']) && $redis_config['port']){
			$this->redis_config['host']	= $redis_config['host'];
			$this->redis_config['port']	= $redis_config['port'];
			$this->redis_config['password']	= $redis_config['password'];
		}
		//$this->redis = new Redis();
		//$this->redis->connect($this->redis_config['host'],$this->redis_config['port']);
		if($this->redis_config['password']){
			//$this->redis->auth($this->redis_config['password']);
		}
	}

	function exists_key( $key = '' ) {
		$key = $this->params['channel'].$key;
		return $this->redis->exists($key);
	}

	function zadd($key, $score, $member){
		$key = $this->params['channel'].$key;
		$this->redis->zAdd( $key , $score, $member);
	}
	

	function hmset($key, $value){
		$key = $this->params['channel'].$key;
		$this->redis->hmset($key, $value);
	}

	function del_key($key=''){
		if($key != '') {
			$key = $this->params['channel'].':'.$key.':*';	
		}else{
			$key = $this->params['channel'].':*';
		}
		$keys = $this->redis->keys($key);//redis集群用不了
		$this->redis->del($keys);
	}
}